﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ASV.Classes;
using System.Net.Mail;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Data;

namespace ASV.Classes
{
    public class showUser
    {
    public showUser(Connection dbConnection)
    {
        object[] values = null;
            MySqlCommand insertCommand = new MySqlCommand("SELECT * FROM `benutzer` LIMIT 0 , 30", dbConnection.getConnection());
            int i = insertCommand.ExecuteNonQuery();
            MySqlDataAdapter adapter = new MySqlDataAdapter(insertCommand);
            DataTable datatable = new DataTable();

            adapter.Fill(datatable);
            for (int x = 0; x < datatable.Rows.Count; x++)
            {
                values = datatable.Rows[x].ItemArray;
            }

            Authentication auth = new Authentication();

            /**
             * Elemente für Mitarbeiter und Administratoren werden ausgeblendet
             */
            ProductsAdmin.Visible = false;
            UserAdmin.Visible = false;
            /**************/

            if (auth.isLoggedIn() == false)
            {
                HeadLogin.Visible = true;
                HeadRegister.Visible = true;

                HeadLogout.Visible = false;
            }
            else
            {
                HeadLogin.Visible = false;
                HeadRegister.Visible = false;

                HeadLogout.Visible = true;

                Benutzer.Text = HttpContext.Current.Session["vorname"].ToString() + " " + HttpContext.Current.Session["nachname"].ToString();
                int userGroup = int.Parse(HttpContext.Current.Session["benutzertyp"].ToString());
                if (auth.checkUserGroup(userGroup, 1))
                {
                    Downloads.Visible = true;
                    Support.Visible = true;
                    Benutzer.Visible = true;

                    if (auth.checkUserGroup(userGroup, 2) == true)
                    {
                        /**
                         * Bereich für die MITARBEITER wird sichbar gemacht
                         */
                        ProductsAdmin.Visible = true;

                        if (auth.checkUserGroup(userGroup, 3) == true)
                        {
                            /**
                             * Bereich für die ADMINISTRATOR wird sichbar gemacht
                             */
                            UserAdmin.Visible = true;
                        }
                    }
                }
            }
        }
    }
}
}